package com.lab.forthreadpool;


import com.lab.util.StringUtil;

import java.security.PublicKey;

/**
 * @author weiwei
 */
public class TransactionOutput {

    public String id;
    public PublicKey reciepient; //also known as the new owner of these coins.
    public double value; //the amount of coins they own
    public String parentTransactionId; //the id of the transaction this output was created in

    //Constructor
    public TransactionOutput(PublicKey reciepient, double value, String parentTransactionId) {
        this.reciepient = reciepient;
        this.value = value;
        this.parentTransactionId = parentTransactionId;
        this.id = StringUtil.applySha256(StringUtil.getStringFromKey(reciepient) + Double.toString(value) + parentTransactionId);
    }

    //验证是不是属于自己
    public boolean isMine(PublicKey publicKey) {
        return (publicKey == reciepient);
    }
}
